//
//  Controller15.swift
//  Swift30Days
//
//  Created by licheng ke on 2017/3/8.
//  Copyright © 2017年 licheng ke. All rights reserved.
//

import UIKit

// Splash 本来是做为Splash用的，但是这个功能融合到ViewController中去了
// 然后SildeMeun需要2个controller做切换，
class Controller15: UIViewController,UITableViewDelegate,UITableViewDataSource {

    var menuItems = ["Everyday Moments", "Popular", "Editors", "Upcoming", "Fresh", "Stock-photos", "Trending"]
    var currentItem = "Everyday Moments"
    
    let tableView = UITableView(frame: UIScreen.main.bounds, style: .plain)
    
    var callBack : ((String) -> ())?
    
    override var preferredStatusBarStyle : UIStatusBarStyle {
        return UIStatusBarStyle.lightContent
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor(white: 0.7, alpha: 1);
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.tableView.backgroundColor = .clear;
        self.view.addSubview(self.tableView);
        self.tableView.separatorStyle = UITableViewCellSeparatorStyle.none
        self.view.backgroundColor = UIColor(red:0.109, green:0.114, blue:0.128, alpha:1)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return menuItems.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
        if cell == nil {
            cell = UITableViewCell(style: .default, reuseIdentifier: "Cell");
        }
        cell?.textLabel?.text = menuItems[indexPath.row]
        cell?.textLabel?.textColor = (menuItems[indexPath.row] == currentItem) ? UIColor.white : UIColor.gray
        cell?.backgroundColor = UIColor.clear
        
        return cell!
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if self.callBack != nil {
            self.callBack!(menuItems[indexPath.row]);
            self.dismiss(animated: true, completion: nil);
        }
    }


}
